package com.lj.ljminsu.merchant.GuanjiaController;
import com.lj.ljminsu.merchant.GuanjiaBean.OderUtil;
import com.lj.ljminsu.merchant.GuanjiaBean.TjOrder;
import com.lj.ljminsu.merchant.GuanjiaService.impl.OderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("order")
@CrossOrigin
public class OderController {
    @Resource
    private OderService oderService;
    @RequestMapping("{condition}")
    @ResponseBody
    public List<TjOrder> tjOrderList(@PathVariable("condition") String conditions){
        String[] Arrays = conditions.split("@");
        int stae=100;
        OderUtil oderUtil = new OderUtil();
        List<TjOrder> orderList =null;
        try {
            for (int i=0;i<Arrays.length;i++
                 ) {
                if (Arrays[0].length()<=1){
                    oderUtil.setFstate(Integer.parseInt(Arrays[0]));
                }else if (Arrays[0].length()==2){
//                    int length = Arrays[0].length();
                    oderUtil.setFstate(null);
                } else if (Arrays[0].equals("入住人")){
                    stae=1;
                    oderUtil.setOderName(stae);
                    oderUtil.setOderTjv(Arrays[1]);
                    break;
                }else if (Arrays[0].equals("订单号")){
                    stae=2;
                    oderUtil.setOderName(stae);
                    String str =Arrays[1];
                    oderUtil.setOderTj(Integer.parseInt(str));
                    break;
                }else if (Arrays[0].equals("入住日期")){
                    stae=3;
                    oderUtil.setOderName(stae);
                    oderUtil.setOderTjv(Arrays[1]);
                    break;
                }else if (Arrays[0].equals("下单日期")){
                    stae=4;
                    oderUtil.setOderName(stae);
                    oderUtil.setOderTjv(Arrays[1]);
                    break;
                }
            }
            orderList = oderService.serch(oderUtil);
        } catch (Exception e) {
            orderList=null;
        }

//        int size = orderList.size();
        return orderList;
    }


}
